/**
 * 
 */

//获得数据库内所有的房源信息以表格的形式显示
$(document).ready(function(){
	$("#houseinfo").click(function (){
		$("#addimgturnhtml").css("display","none");
		$("#xianshineirong").css("display","block");
		$("#xianshineirong").empty();

			$.ajax({
			url: "/airbnb/houseinfochange.do",
			async: false,
		   	type: "POST",
		   	error: function (){
		   		alert("数据提交失败")
		   	},
		   	success: function(json){
		   		var html = "<table id='housetab' class='layui-table'>";
			   	
			   	html+="<colgroup>";
			   	html+="<col width='150'>";
			   	html+="<col width='200'>";
			   	html+="<col>";
			   	html+="</colgroup>";
			   	html+="<thead>";
			   	html+="<tr>";
			   	html+="<th>id</th>";
			   	html+="<th>房名</th>";
			   	html+="<th>房源类型</th>";
			   	html+="<th>出租类型</th>";
			   	html+="<th>房东</th>";
			   	html+="<th>房客数量</th>";
			   	html+="<th>房间数</th>";
			   	html+="<th>床数</th>";
			   	html+="<th>卫生间数</th>";
			   	html+="<th>卫生间是否私有</th>";
			   	html+="<th>地区</th>";
			   	html+="<th>地址</th>";
			   	html+="<th>单价</th>";
			   	html+="<th>房屋照片</th>";
			   	html+="<th>是否显示</th>";
			   	html+="</tr>";
				html+="</thead>";
				html+="<tbody id='housetabbody'>";
				html+="</tbody>";
				html+="</table>";
			  
			   	$("#xianshineirong").append(html);
		   		for(var i = 0;i<json.length;i++){
		   			var html2 = "<tr>";
		   			html2+="<td>";
		   			html2+=json[i].houseid;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+=json[i].housename;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+=json[i].htid;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+=json[i].rtid;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+=json[i].userid;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+=json[i].unum;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+=json[i].roomnum;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+=json[i].bednum;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+=json[i].wcnum;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+=json[i].iswcp;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+=json[i].area;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+=json[i].adress;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+=json[i].price;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+="<img src=/airbnb"+json[i].photo+">";
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+="<input class='housechangecheck' type='checkbox' value="+json[i].houseid+">";
		   			html2+="</td>";
		   			html2+="</tr>";
		   			$("#housetabbody").append(html2);
		   		}
		   		 
		   		var html3 = "<tr id='housechangesub'>";
	   			html3+="<td colspan='15'>";
	   			html3+="<button id='housechangebtn' class ='housechangebtn'>更换</button>";
	   			html3+="</td>";
	   			html3+="</tr>";
	   			$("#housetabbody").append(html3);
		   	}
		});
	});
	
	//将选中房源查询，并存入房源显示表中
	$(document).on("click","#housechangebtn",function (){
		var houseid2 = [];
		var a = $("input[type=checkbox]:checked");
		for(var i = 0;i<a.length;i++){
			houseid2.push(a[i].value);
		}
		$.ajax({
            async : false,
            cache : false,
            traditional: true,
            type : 'POST',
            data : {
            	houseid2:houseid2
            },
            url : "/airbnb/savehouse.do",// 请求的action路径
            error : function() {// 请求失败处理函数
            	alert("?")
            },
            success : function(data) {
               alert("1");
            }
        });
	});
	
	
	//查询房源显示表中的所有房源，显示
	$("#housedisplay").click(function (){
		$("#addimgturnhtml").css("display","none");
		$("#xianshineirong").css("display","block");
		$("#xianshineirong").empty();
			$.ajax({
			url: "/airbnb/housedisplay.do",
			async: false,
		   	type: "POST",
		   	error: function (){
		   		alert("数据提交失败")
		   	},
		   	success: function(json){
		   		var html = "<table id='housetab' class='layui-table'>";
			   	
			   	html+="<colgroup>";
			   	html+="<col width='150'>";
			   	html+="<col width='200'>";
			   	html+="<col>";
			   	html+="</colgroup>";
			   	html+="<thead>";
			   	html+="<tr>";
			   	html+="<th>id</th>";
			   	html+="<th>房名</th>";
			   	html+="<th>房源类型</th>";
			   	html+="<th>出租类型</th>";
			   	html+="<th>房东</th>";
			   	html+="<th>房客数量</th>";
			   	html+="<th>房间数</th>";
			   	html+="<th>床数</th>";
			   	html+="<th>卫生间数</th>";
			   	html+="<th>卫生间是否私有</th>";
			   	html+="<th>地区</th>";
			   	html+="<th>地址</th>";
			   	html+="<th>单价</th>";
			   	html+="<th>房屋照片</th>";
			   	html+="<th>是否显示</th>";
			   	html+="</tr>";
				html+="</thead>";
				html+="<tbody id='housetabbody'>";
				html+="</tbody>";
				html+="</table>";
			  
			   	$("#xianshineirong").append(html);
		   		for(var i = 0;i<json.length;i++){
		   			var html2 = "<tr>";
		   			html2+="<td>";
		   			html2+=json[i].houseid;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+=json[i].housename;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+=json[i].htid;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+=json[i].rtid;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+=json[i].userid;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+=json[i].unum;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+=json[i].roomnum;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+=json[i].bednum;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+=json[i].wcnum;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+=json[i].iswcp;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+=json[i].area;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+=json[i].adress;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+=json[i].price;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+="<img src=/airbnb"+json[i].photo+">";
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+="<input class='housechangecheck' type='checkbox' value="+json[i].houseid+">";
		   			html2+="</td>";
		   			html2+="</tr>";
		   			$("#housetabbody").append(html2);
		   		}
		   		 
		   		var html3 = "<tr id='housechangesub2'>";
	   			html3+="<td colspan='15'>";
	   			html3+="<button id='housechangebtn2' class ='housechangebtn'>删除正在显示的房源</button>";
	   			html3+="</td>";
	   			html3+="</tr>";
	   			$("#housetabbody").append(html3);
		   	}
		});
	});
	
	
	//将选中的房源删除
	$(document).on("click","#housechangebtn2",function (){
		var houseid3 = [];
		var a1 = $("input[type=checkbox]:checked");
		for(var i = 0;i<a1.length;i++){
			houseid3.push(a1[i].value);
		}
		$.ajax({
            async : false,
            cache : false,
            traditional: true,
            type : 'POST',
            data : {
            	houseid3:houseid3
            },
            url : "/airbnb/deletehouse.do",// 请求的action路径
            error : function() {// 请求失败处理函数
            	alert("?")
            },
            success : function(data) {
               alert(data);
            }
        });
	});
	
	
	//点击显示添加轮播界面
	$("#addimgturn").click(function(){
		$("#xianshineirong").css("display","none");
		$("#xianshineirong").empty();
		$("#addimgturnhtml").css("display","block");

	});
	
	//上传轮播图的标题和信息
	$("#imgturnbtn").click(function(){
		var imgdes = $("#imgdesarea").val();
		var imgtitle = $("#imgtitle").val();
		$.ajax({
            async : false,
            cache : false,
            traditional: true,
            type : 'POST',
            data :{"imgdes":imgdes,"imgtitle":imgtitle},
            url : "/airbnb/imgturn.do",// 请求的action路径
            error : function() {// 请求失败处理函数
            	alert("?")
            },
            success : function(data) {
               alert(data);
            }
        });
	});
	
	//显示所有的轮播图
	$("#imgturn").click(function (){
		$("#addimgturnhtml").css("display","none");
		$("#xianshineirong").css("display","block");
		$("#xianshineirong").empty();
			$.ajax({
			url: "/airbnb/imgturndisplay.do",
			async: false,
		   	type: "POST",
		   	error: function (){
		   		alert("数据提交失败")
		   	},
		   	success: function(json){
		   		var html = "<table id='housetab' class='layui-table'>";
			   	html+="<colgroup>";
			   	html+="<col width='150'>";
			   	html+="<col width='200'>";
			   	html+="<col>";
			   	html+="</colgroup>";
			   	html+="<thead>";
			   	html+="<tr>";
			   	html+="<th>id</th>";
			   	html+="<th>轮播描述</th>";
			   	html+="<th>轮播图</th>";
			   	html+="<th>是否显示</th>";
			   	html+="</tr>";
				html+="</thead>";
				html+="<tbody id='housetabbody'>";
				html+="</tbody>";
				html+="</table>";
			  
			   	$("#xianshineirong").append(html);
		   		for(var i = 0;i<json.length;i++){
		   			var html2 = "<tr>";
		   			html2+="<td>";
		   			html2+=json[i].imgid;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+=json[i].imgdes;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+="<img src=/airbnb"+json[i].imgurl+">";
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+="<input class='housechangecheck' type='checkbox' value="+json[i].imgid+">";
		   			html2+="</td>";
		   			html2+="</tr>";
		   			$("#housetabbody").append(html2);
		   		}
		   		 
		   		var html3 = "<tr id='housechangesub3'>";
	   			html3+="<td colspan='15'>";
	   			html3+="<button id='housechangebtn3' class ='housechangebtn'>更换</button>";
	   			html3+="</td>";
	   			html3+="</tr>";
	   			$("#housetabbody").append(html3);
		   	}
		});
	});
	
	
	
	//将选中轮播图查询，并存入轮播图显示表中
	$(document).on("click","#housechangebtn3",function (){
		var imgid2 = [];
		var a = $("input[type=checkbox]:checked");
		for(var i = 0;i<a.length;i++){
			imgid2.push(a[i].value);
		}
		$.ajax({
            async : false,
            cache : false,
            traditional: true,
            type : 'POST',
            data : {
            	imgid2:imgid2
            },
            url : "/airbnb/saveimgturn.do",// 请求的action路径
            error : function() {// 请求失败处理函数
            	alert("?")
            },
            success : function(data) {
               alert("1");
            }
        });
	});
	
	
	$("#imgturndisplay").click(function (){
		$("#addimgturnhtml").css("display","none");
		$("#xianshineirong").css("display","block");
		$("#xianshineirong").empty();
		$("#xianshigushineirong").empty();
			$.ajax({
			url: "/airbnb/imgturndisplaytwo.do",
			async: false,
		   	type: "POST",
		   	error: function (){
		   		alert("数据提交失败")
		   	},
		   	success: function(json){
		   		var html = "<table id='housetab' class='layui-table'>";
			   	html+="<colgroup>";
			   	html+="<col width='150'>";
			   	html+="<col width='200'>";
			   	html+="<col>";
			   	html+="</colgroup>";
			   	html+="<thead>";
			   	html+="<tr>";
			   	html+="<th>id</th>";
			   	html+="<th>轮播描述</th>";
			   	html+="<th>轮播图</th>";
			   	html+="<th>是否显示</th>";
			   	html+="</tr>";
				html+="</thead>";
				html+="<tbody id='housetabbody'>";
				html+="</tbody>";
				html+="</table>";
			  
			   	$("#xianshineirong").append(html);
		   		for(var i = 0;i<json.length;i++){
		   			var html2 = "<tr>";
		   			html2+="<td>";
		   			html2+=json[i].imgid;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+=json[i].imgdes;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+="<img src=/airbnb"+json[i].imgurl+">";
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+="<input class='housechangecheck' type='checkbox' value="+json[i].imgid+">";
		   			html2+="</td>";
		   			html2+="</tr>";
		   			$("#housetabbody").append(html2);
		   		}
		   		 
		   		var html3 = "<tr id='housechangesub4'>";
	   			html3+="<td colspan='15'>";
	   			html3+="<button id='housechangebtn4' class ='housechangebtn'>更换</button>";
	   			html3+="</td>";
	   			html3+="</tr>";
	   			$("#housetabbody").append(html3);
		   	}
		});
	});
	
	//将选中的轮播图删除
	$(document).on("click","#housechangebtn4",function (){
		var imgid3 = [];
		var a1 = $("input[type=checkbox]:checked");
		for(var i = 0;i<a1.length;i++){
			imgid3.push(a1[i].value);
		}
		$.ajax({
            async : false,
            cache : false,
            traditional: true,
            type : 'POST',
            data : {
            	imgid3:imgid3
            },
            url : "/airbnb/deleteimgturn.do",// 请求的action路径
            error : function() {// 请求失败处理函数
            	alert("?")
            },
            success : function(data) {
               alert(data);
            }
        });
	});
});
//故事
$(document).ready(function(){
	$("#storyinfo").click(function(){
		$("#xianshineirong").css("display","block");
		
		$("#xianshineirong").empty();
		$.ajax({
			url: "/airbnb/storyinfochange.do",
			async: false,
		   	type: "POST",
		   	error: function (){
		   		alert("数据提交失败")
		   	},success: function(json){
				var html = "<table id='storytab' class='layui-table'>";
			   	
			   	html+="<colgroup>";
			   	html+="<col width='150'>";
			   	html+="<col width='200'>";
			   	html+="<col>";
			   	html+="</colgroup>";
			   	html+="<thead>";
			   	html+="<tr>";
			   	html+="<th>作者姓名</th>";
			   	html+="<th>房源名称</th>";
			   	html+="<th>故事名称</th>";
			   	html+="<th>故事内容</th>";
			 	html+="<th>点赞数</th>";
				html+="<th>故事类型</th>";
			   	//html+="<th style='width:1000px'>故事照片 </th>";
			   	html+="<th style='width:125px'>是否显示</th>";
			   	html+="</tr>";
				html+="</thead>";
				html+="<tbody id='storytabbody'>";
				html+="</tbody>";
			  
			   	$("#xianshineirong").append(html);
		   		for(var i = 0;i<json.length;i++){
		   			var html2 = "<tr>";
		   			html2+="<td>";
		   			html2+=json[i].user.uname;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+=json[i].house.housename;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+=json[i].title;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+=json[i].content;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+=json[i].znum;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+=json[i].stotype.stname;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+="<input type='checkbox' value="+json[i].stoid+">";
		   			html2+="</td>";
		   			html2+="</tr>";
		   			$("#storytabbody").append(html2);

		   		}	
		   		var html3 = "<tr id='storychangesub'>";
	   			html3+="<td colspan='15'>";
	   			html3+="<button id='storychangebtn'>更换</button>";
	   			html3+="</td>";
	   			html3+="</tr>";
	   			$("#storytabbody").append(html3);
		   	}
		});
	});
	$(document).on("click","#storychangebtn",function (){
		var storyid2 = [];
		var a = $("input[type=checkbox]:checked");
		for(var i = 0;i<a.length;i++){
			storyid2.push(a[i].value);
		}
		$.ajax({
            async : false,
            cache : false,
            traditional: true,
            type : 'POST',
            data : {
            	storyid2:storyid2
            },
            url : "/airbnb/savestory.do",// 请求的action路径
            error : function() {// 请求失败处理函数
            	alert("精彩故事修改失败")
            },
            success : function(data) {
               alert("精彩故事修改成功");
            }
        });
	});
	
	$("#storydisplay").click(function (){
		$("#xianshineirong").css("display","block");
		$("#xianshineirong").empty();
		
			$.ajax({
			url: "/airbnb/storydisplay.do",
			async: false,
		   	type: "POST",
		   	error: function (){
		   		alert("数据提交失败")
		   	},
		   	success: function(json){
		   		var html = "<table id='storytab' class='layui-table'>";
			   	
			   	html+="<colgroup>";
			   	html+="<col width='150'>";
			   	html+="<col width='200'>";
			   	html+="<col>";
			   	html+="</colgroup>";
			   	html+="<thead>";
			   	html+="<tr>";
			   	html+="<th>作者姓名</th>";
			   	html+="<th>房源名称</th>";
			   	html+="<th>故事名称</th>";
			   	html+="<th>故事内容</th>";
			 	html+="<th>点赞数</th>";
				html+="<th>故事类型</th>";
			   	//html+="<th style='width:1000px'>故事照片 </th>";
			   	html+="<th style='width:125px'>是否删除</th>";
			   	html+="</tr>";
				html+="</thead>";
				html+="<tbody id='storysettabbody'>";
				html+="</tbody>";
			  
			   	$("#xianshineirong").append(html);
		   		for(var i = 0;i<json.length;i++){
		   			var html2 = "<tr>";
		   			html2+="<td>";
		   			html2+=json[i].user.uname;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+=json[i].house.housename;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+=json[i].title;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+=json[i].content;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+=json[i].znum;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+=json[i].stotype.stname;
		   			html2+="</td>";
		   			html2+="<td>";
		   			html2+="<input type='checkbox' value="+json[i].stoid+">";
		   			html2+="</td>";
		   			html2+="</tr>";
		   			$("#storysettabbody").append(html2);
		   		}
		   		 
		   		var html3 = "<tr id='storychangesub2'>";
	   			html3+="<td colspan='15'>";
	   			html3+="<button id='storychangebtn2'>删除正在显示的故事</button>";
	   			html3+="</td>";
	   			html3+="</tr>";
	   			$("#storysettabbody").append(html3);
		   	}
		});
	});
	$(document).on("click","#storychangebtn2",function (){
		var storyid3 = [];
		var a = $("input[type=checkbox]:checked");
		for(var i = 0;i<a.length;i++){
			storyid3.push(a[i].value);
		}
		$.ajax({
            async : false,
            cache : false,
            traditional: true,
            type : 'POST',
            data : {
            	storyid3:storyid3
            },
            url : "/airbnb/deletestory.do",// 请求的action路径
            error : function() {// 请求失败处理函数
            	alert("精彩故事删除失败")
            },
            success : function(data) {
               alert("精彩故事删除成功");
            }
        });
	});
});